package com.me.jingdongshop.ui.activity;

import android.content.Intent;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;

/**
 * Created by ldl on 2017/5/8.
 * 支付方式界面
 */

public class ShopcartPaymodeActivity extends BaseActivity {
    public static final int RESULT_CODE = 02;
    public static final int Cash = 0;
    public static final int POS = 1;
    public static final int ALIPAY = 2;
    private TextView tvPaymentModeBack;      // 支付方式返回
    private TextView tvPaymentCash;          // 支付方式-现金
    private TextView tvPaymentPos;           // 支付方式-Pos
    private TextView tvPaymentPaybao;       // 支付方式-支付宝
    private ImageView ivPaymentCaseCheck;   // 现金支付勾选
    private ImageView ivPaymentPosCheck;   // Pos支付勾选
    private ImageView ivPaymentPaybaoCheck;   // 支付宝支付勾选
    private TextView tvPaymentConfirm;        // 确定

    private int currentCheckMode = Cash;

    @Override
    public int getLayoutRes() {
        return R.layout.activity_shopcart_payment_mode;
    }

    @Override
    public void initView() {
        tvPaymentModeBack = (TextView) findViewById(R.id.tv_payment_mode_back);
        tvPaymentCash = (TextView) findViewById(R.id.tv_payment_cash);
        tvPaymentPos = (TextView) findViewById(R.id.tv_payment_pos);
        tvPaymentPaybao = (TextView) findViewById(R.id.tv_payment_paybao);
        ivPaymentCaseCheck = (ImageView) findViewById(R.id.iv_payment_case_check);
        ivPaymentPosCheck = (ImageView) findViewById(R.id.iv_payment_pos_check);
        ivPaymentPaybaoCheck = (ImageView) findViewById(R.id.iv_payment_paybao_check);
        tvPaymentConfirm = (TextView) findViewById(R.id.tv_payment_confirm);
    }

    @Override
    public void initListener() {
        tvPaymentModeBack.setOnClickListener(this);
        tvPaymentCash.setOnClickListener(this);
        tvPaymentPos.setOnClickListener(this);
        tvPaymentPaybao.setOnClickListener(this);
        ivPaymentCaseCheck.setOnClickListener(this);
        ivPaymentPosCheck.setOnClickListener(this);
        ivPaymentPaybaoCheck.setOnClickListener(this);
        tvPaymentConfirm.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v, int id) {
        switch (id) {
            case R.id.tv_payment_mode_back:
                finish();
            break;
            case R.id.tv_payment_cash:
            case R.id.iv_payment_case_check:
                if(Cash != currentCheckMode){
                    currentCheckMode = Cash;
                    ivPaymentCaseCheck.setBackgroundResource(R.drawable.ischeck);
                    ivPaymentPosCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivPaymentPaybaoCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    return;
                }
                break;
            case R.id.tv_payment_pos:
            case R.id.iv_payment_pos_check:
                if(POS != currentCheckMode){
                    currentCheckMode = POS;
                    ivPaymentPosCheck.setBackgroundResource(R.drawable.ischeck);
                    ivPaymentCaseCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivPaymentPaybaoCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    return;
                }
                break;
            case R.id.tv_payment_paybao:
            case R.id.iv_payment_paybao_check:
                if(ALIPAY != currentCheckMode){
                    currentCheckMode = ALIPAY;
                    ivPaymentPaybaoCheck.setBackgroundResource(R.drawable.ischeck);
                    ivPaymentPosCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    ivPaymentCaseCheck.setBackgroundResource(R.drawable.white_pink_circle);
                    return;
                }
                break;
            case R.id.tv_payment_confirm:
                Intent intent = new Intent();
                String result = "";
                if(currentCheckMode == Cash){
                    result = "到付-现金";
                }else if(currentCheckMode == POS){
                    result = "到付-POS";
                }else {
                    result = "支付宝";
                }
                intent.putExtra("payMode",result);
                setResult(RESULT_CODE,intent);
                break;
        }
    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {

    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
